<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>北京联合大学</title>
</head>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="https://at.alicdn.com/t/font_835526_xufba1hg66.css"> -->
<link rel="stylesheet" href="https://at.alicdn.com/t/font_835526_uzbxo9d25is.css">
<link rel="stylesheet" href="../../css/Initialization.css">
<link rel="stylesheet" href="../../css/commen.css">
<link rel="stylesheet" href="../../css/UploadResults.css">
<body>
<div id="content">
    <div class="initer">
        <!-- 具体内容 -->
        <div class="bread">
            <div class="plain">管理配置</div>
            <div class="plain">
                <i class="iconfont icon-right"></i>
            </div>
            <div class="plain current"><a href="../depart/list" style="color: #0156a8;">组织架构配置</a></div>
            <div class="plain">
                <i class="iconfont icon-right"></i>
            </div>
            <div class="plain current" >年级单元管理(<span th:text="${depart.departname}"></span>)</div>
            <div class="center-button" onclick="saveMenuConfig()">保存</div>
            <input type="hidden" id="gradeid" th:value="${depart.id}"/>
        </div>
        <div class="teacherlookwork teacherlookteam teacherHuiZong">
            <table class="table">
                <tr class="tabletitle">
                    <td>是否启用 <input type="checkbox" id="allchecks" />全选</td>
                    <td>单元名称</td>
                    <td>责任老师</td>
                </tr>
                <tr th:each="item : ${menulist}">
                    <td><input type="checkbox" name="checks" th:value="${item.id}"/> </td>
                    <td th:text="${item.menuname}">单元名称</td>
                    <td>
                        <select id="teacher" name="teacher">
                            <option value="0">请选择</option>
                            <option th:each="person : ${teacherList}" th:value="${person.id}" th:text="${person.realname}">请选择</option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/commen.js"></script>
<script th:inline="javascript">
    function saveMenuConfig(){
        var menuids = "";
        var teachers = "";
        var teacherNames = "";
        $('input[name="checks"]:checked').each(function(){
            menuids += $(this).val() + ",";
            var obj = $(this).parent().parent().find("#teacher");
            teachers += $(obj).val() + ",";
            teacherNames += $(obj).find("option:selected").text() + ",";
        });
        if(menuids.length == 0){
            alert("请选择单元")
        }else{
            var gradeid = $("#gradeid").val();
            menuids = menuids.substring(0,menuids.length-1);
            teachers = teachers.substring(0,teachers.length-1);
            teacherNames = teacherNames.substring(0,teacherNames.length-1);
            $.ajax({
                type : "POST",
                url : "setMenuConfig",
                data : {gradeid:gradeid, menuids:menuids, teachers: teachers,teacherNames: teacherNames},
                dataType : "json",
                success : function(json) {
                    if(json.state == success){
                        alert(json.result);
                        history.back();
                    }else{
                        alert(json.result);
                    }
                },
                error:function(msg){
                    alert("程序出错，请联系管理员");
                }
            });
        }
    }
    $(function () {
        var configs = [[${configs}]];
        console.log(configs)
        $('input[name="checks"]').each(function(){
            for(var i=0;i<configs.length;i++){
                if(configs[i].menuidStr == $(this).val()){
                    $(this).prop("checked", true);
                    $(this).parent().parent().find("#teacher").val(configs[i].personidStr)
                }
            }
        });


        $("#allchecks").click(function () {
            if (this.checked) {
                $("input[name=checks]:checkbox").prop("checked", true);
            } else {
                $("input[name=checks]:checkbox").prop("checked", false);
            }
        });
    });
</script>
</body>
</html>

